﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;

namespace Gtkj.CMS.Common
{
    public class NPOIHelper
    {
        /// <summary>
        /// 标题样式
        /// </summary>
        /// <param name="workbook"></param>
        /// <returns></returns>
        public static HSSFCellStyle GetStyleTitle(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            HSSFFont font = (HSSFFont)workbook.CreateFont();
            font.FontHeight = 20 * 20;
            style.SetFont(font);
            return style;
        }

        /// <summary>
        /// 报表期
        /// </summary>
        /// <param name="workbook"></param>
        /// <returns></returns>
        public static HSSFCellStyle GetStyleReportPeriod(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            //HSSFFont font = (HSSFFont)workbook.CreateFont();
            //font.FontHeight = 20 * 20;
            //style.SetFont(font);
            return style;
        }
        /// <summary>
        /// 数据区
        /// </summary>
        /// <param name="workbook"></param>
        /// <returns></returns>
        public static HSSFCellStyle GetStyleBody(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            return style;
        }
        /// <summary>
        /// 汇报期
        /// </summary>
        /// <param name="workbook"></param>
        /// <returns></returns>
        public static HSSFCellStyle GetStyleReportDate(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Right;
            //HSSFFont font = (HSSFFont)workbook.CreateFont();
            //font.FontHeight = 20 * 20;
            //style.SetFont(font);
            return style;
        }
        /// <summary>
        /// 金额样式
        /// </summary>
        /// <returns>#,##0.00</returns>
        public static HSSFCellStyle GetStyleMoney(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            HSSFDataFormat format = (HSSFDataFormat)workbook.CreateDataFormat();
            style.DataFormat = format.GetFormat("#,##0.00");
            style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            return style;
        }

        /// <summary>
        /// 表头样式
        /// </summary>
        /// <param name="workbook"></param>
        /// <returns></returns>
        public static HSSFCellStyle GetStyleHeader(HSSFWorkbook workbook)
        {
            HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            style.IsLocked = true;
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
            style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;

            HSSFFont font = (HSSFFont)workbook.CreateFont();
            font.FontName = "黑体";
            font.FontHeightInPoints = 15;
            style.SetFont(font);
            return style;
        }

    }
}
